//
//  UIBarButtonItem+Extation.swift
//  微博项目001
//
//  Created by 樊武超 on 16/4/10.
//  Copyright © 2016年 樊武超. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(imageName:String?,title: String?=nil,target: AnyObject?,selector: Selector) {
        self.init()
        let butn=UIButton()
        
        if let img=imageName {
        butn.setImage(UIImage(named: img), forState: .Normal)
        butn.setImage(UIImage(named: img+"_highlighted"), forState: .Highlighted)
            butn.imageEdgeInsets=UIEdgeInsetsMake(0, -5, 0, 5)
        }
        butn.setTitle(title, forState: .Normal)
        
        butn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        
        butn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        butn.addTarget(target, action: selector, forControlEvents: .TouchUpInside)
        
        butn.sizeToFit()
        
        customView=butn
        
    }



}
